﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMatysiak.Methods
{
    public static class EnumExtensions
    {
        public static T ToEnum<T>(this string s)
        {
            return (T)Enum.Parse(typeof(T), s, true);
        }

        public static IEnumerable<string> EnumToList<T>()
        {
            Type enumType = typeof(T);

            if (enumType.BaseType != typeof(Enum))
                throw new ArgumentException("T must be of type System.Enum");

            Array enumValArray = Enum.GetValues(enumType);
            List<string> enumValList = new List<string>(enumValArray.Length);

            foreach (var val in enumValArray)
            {
                enumValList.Add(val.ToString());
            }

            return enumValList;
        }

        public static IEnumerable<T> EnumValues<T>()
        {
            return (IEnumerable<T>)Enum.GetValues(typeof(T));
        }
    }
}
